<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>欢迎页面</title>
  <style>
    body {
      font-family: "Microsoft YaHei", sans-serif;
      padding: 30px;
      background-color: #f5f6fa;
    }
    .welcome-container {
      max-width: 800px;
      margin: 0 auto;
    }
    .welcome-header {
      text-align: center;
      margin-bottom: 40px;
    }
    h1 {
      color: #2c3e50;
      margin-bottom: 20px;
      font-size: 28px;
    }
    .welcome-content {
      background-color: white;
      padding: 30px;
      border-radius: 8px;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    }
    .welcome-info {
      color: #34495e;
      line-height: 1.8;
      margin-bottom: 20px;
    }
    .system-info {
      background-color: #f8f9fa;
      padding: 20px;
      border-radius: 6px;
      margin-top: 30px;
    }
    .info-item {
      margin-bottom: 10px;
      color: #576574;
    }
    .info-item strong {
      color: #2c3e50;
      margin-right: 10px;
    }
    .current-time {
      text-align: right;
      color: #7f8c8d;
      font-size: 14px;
      margin-top: 20px;
    }
  </style>
</head>
<body>
<div class="welcome-container">
  <div class="welcome-header">
    <h1>欢迎使用教务管理系统</h1>
  </div>

  <div class="welcome-content">
    <div class="welcome-info">
      <%
        // 获取session中的用户信息
        String username = (String) session.getAttribute("username");
        if (username == null) {
          username = "管理员";
        }
      %>
      <p>尊敬的 <strong><%=username%></strong>，欢迎回来！</p>
      <p>您可以通过左侧菜单访问各项管理功能。</p>
    </div>

    <div class="system-info">
      <div class="info-item">
        <strong>系统版本：</strong>1.0.0
      </div>
      <div class="info-item">
        <strong>上次登录时间：</strong>
        <%
          String lastLoginTime = (String) session.getAttribute("lastLoginTime");
          if (lastLoginTime != null) {
            out.print(lastLoginTime);
          } else {
            out.print("首次登录");
          }
        %>
      </div>
      <div class="info-item">
        <strong>浏览器信息：</strong>
        <%=request.getHeader("User-Agent")%>
      </div>
    </div>

    <div class="current-time">
      当前时间：
      <%
        java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        out.print(formatter.format(new java.util.Date()));
      %>
    </div>
  </div>
</div>

<script>
  // 更新当前时间
  function updateTime() {
    const timeElement = document.querySelector('.current-time');
    setInterval(() => {
      const now = new Date();
      const formatter = new Intl.DateTimeFormat('zh-CN', {
        year: 'numeric',
        month: '2-digit',
        day: '2-digit',
        hour: '2-digit',
        minute: '2-digit',
        second: '2-digit',
        hour12: false
      });
      timeElement.textContent = '当前时间：' + formatter.format(now);
    }, 1000);
  }

  // 页面加载完成后执行
  document.addEventListener('DOMContentLoaded', updateTime);
</script>
</body>
</html>